package com.huawei.smartcity0102.util;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
 * @author ZengYunyi
 * @description:
 * @date :2022/1/2 14:03
 */
public abstract class Ad<T> extends RecyclerView.Adapter<Ad.VH>{
    protected abstract void initD(View vi,T t,int p);
    int layId;
    List<T> tl;

    public Ad(int layId, List<T> tl) {
        this.layId = layId;
        this.tl = tl;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new VH(LayoutInflater.from(parent.getContext()).inflate(layId,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        initD(holder.itemView,tl.get(position),position);
    }

    @Override
    public int getItemCount() {
        return tl.size();
    }

    static class VH extends RecyclerView.ViewHolder{

        public VH(@NonNull View itemView) {
            super(itemView);
        }
    }
}
